# -*-coding:utf-8-*-
from utils import read_txt,cut_sent,read_hed,read_word
from Syntactic_Analysis import ParseResult
import regex
'''
判断形容词谓语句
主||“很”+形
主||形
主||形+“了”
主||“不/没（有）”+形
主||数量词组+形
主||状+形
状+主||形
主||形容词重叠式
主||形容词重叠式+“的”
主||带辅助成分的形容词+“的”
主||形+补
'''
def find_overlapping_adj(str):
    flag = 0
    for i in range(len(str)):
        if str.count(str[i]) > 1:
            flag =1
    return  flag

def judge_type(hed_info, modifi_info, fenci_res, pos_res):
    adv_info = modifi_info['adv_info']  # ADV信息
    mt_info = modifi_info['mt_info']    # MT信息
    sbv_info = modifi_info['sbv_info']  # SBV成分
    cmp_info = modifi_info['cmp_info']  # CMP成分
    att_info = modifi_info['att_info']
    sbv_h = read_hed(sbv_info,hed_info['word'])
    noun_lst = ['n', 'f', 's', 't', 'nr', 'ns', 'nt', 'nw', 'nz', 'r', 'an', 'vn', 'PER']
    verb_lst = ['v', 'vd', 'vn']
    adj_lst = ['a', 'ad', 'an']
    quan_lst = ['m', 'q']

    type_lst = ['主||“很”+形', '主||形', '主||形+“了”', '主||“不/没（有）”+形',
                '主||数量词组+形', '主||状+形', '状+主||形', '主||形容词重叠式', '主||形容词重叠式+“的”',
                '主||带辅助成分的形容词+“的”', '主||形+补', '其他句型']
    type_id = len(type_lst) - 1
    if hed_info['pos'] in adj_lst + noun_lst:
        if [quan for quan in adv_info + att_info if
            quan['pos'] in quan_lst and quan['num'] < fenci_res.index(quan['hed_word']) and quan['num'] < hed_info['num'] - 1]:
            type_id = 4
            return type_lst[type_id]
        if [cmp for cmp in cmp_info if cmp['num'] > hed_info['num'] - 1]:
            # res = []
            # for cmp in cmp_info:
            #     if cmp
            #         res.appeng(cmp)
            type_id = 10
            return type_lst[type_id]
        if find_overlapping_adj(hed_info['word']):
            if [mt for mt in mt_info if mt['word'] == '的' and mt['num'] > hed_info['num'] - 1]:
                type_id = 8
                return type_lst[type_id]
            type_id = 7
            return  type_lst[type_id]
        if [mt for mt in mt_info if mt['word'] == '的' and mt['num'] > hed_info['num'] - 1]:
            type_id = 9
            return type_lst[type_id]
        if [adv for adv in adv_info if adv['word'] in ['不','没','没有'] and adv['num'] < hed_info['num'] - 1]:
            type_id = 3
            return type_lst[type_id]
        if sbv_h and [adv for adv in adv_info if adv['num'] < sbv_h['num']]:
            type_id = 6
            return type_lst[type_id]
        if [adv for adv in adv_info if adv['num'] < hed_info['num'] - 1]:
            type_id = 5
            return  type_lst[type_id]
        if [mt for mt in mt_info if mt['word'] == '了' and mt['hed_word'] == hed_info['word']]:
            type_id = 2
            return type_lst[type_id]
        type_id = 1
        return type_lst[type_id]
    if [adv for adv in adv_info if adv['word'] == '很' and adv['hed_word'] == hed_info['word']]:
        type_id = 0
        return type_lst[type_id]
    return type_lst[type_id]
if __name__ == '__main__':
    path = './data/test_adjpre.txt'  # 读取数据
    sentences = read_txt(path)
    for sent in sentences:
        print('*' * 125)
        print(sent)
        fenci_res, pos_res, ddp_res = cut_sent(sent)
        pr = ParseResult(fenci_res, pos_res, ddp_res)
        print('分词：', fenci_res)
        print('词性：', pos_res)
        print('句法：', ddp_res)
        modifi_info = pr.get_modifi_info()
        hed_info = pr.get_hed_info()
        print(judge_type(hed_info, modifi_info, fenci_res, pos_res))
